{extend name="layout"}
{block name="style"}
<style>
body{min-width: inherit;background-color: #fff;overflow-x: hidden;}
.teacher{display: none;}
.layui-layout-admin .layui-body{top:10px;}
form{padding:50px 0;}
.layui-footer{width: 100%;position: fixed;bottom: 0;padding:10px 0px;background-color: #eee;text-align: center;}
</style>
{/block}
{block name="header"}{/block}
{block name="menu"}{/block}
{block name="more"}{/block}
{block name="footer"}

{/block}
{block name="main"}
<form class="layui-form" action="" method="post">
    
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">新闻标题</label>
      <div class="layui-input-inline">
        <select name="news_id" required lay-verify="required" lay-filter="" lay-search='true' >
          <option value="" >搜索新闻</option>
          {volist name="news" id="vo"}
          <option value="{$vo['id']}">{$vo['title']}</option>
          {/volist}
        </select>
      </div>
    </div>
  </div>
   
  
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">标题</label>
      <div class="layui-input-inline">
        <input type="text" name="name" placeholder="" required lay-verify="required" autocomplete="off" class="layui-input">
      </div>
    </div>
  </div>
    
    
    <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">附件</label>
      <div class="layui-upload layui-input-inline">
        <button type="button" class="layui-btn layui-btn-primary" id="files">上传文件</button>
        <input class="layui-upload-file" type="file" name="files">
        <div class="layui-upload-list" id="files-list">
          {if !empty($data)}
          {volist name="data['files']" id='vo'}
          <div style="width: 68px;position: relative;float:left;margin-right:5px;margin-bottom:5px;">
            <img src="{$vo['cover']}" alt="" width="68" height="68" style="border:1px solid #eee;">
            <input type="hidden" name="files[]" value="{$vo['src']}" lay-verify="required" autocomplete="off" class="layui-input">
            <div onclick="((this.parentNode).parentNode).removeChild(this.parentNode);" style="background-color:#000;position:absolute;top:0;right:0;padding:2px;"><i class="layui-icon" style="color:#fff;">&#x1007;</i></div>
          </div>
          {/volist}
          {/if}
        </div>
        <div id="files-err"></div>
      </div>
      <script>
        layui.use(['jquery','upload'],function(){
          var $ = layui.jquery;
          var upload = layui.upload;
          var uploadInst = upload.render({
            elem: '#files',
            url: '{:url('upload/file')}',
            size:30*1024,
            accept:'file',
            before: function(obj){

            },
            done: function(res){
              if(res.code == 1){
                var html = '';
                    html += '<div style="width: 68px;position: relative;float:left;margin-right:5px;margin-bottom:5px;">';
                    html += '<img src="'+res.cover+'" alt="" width="68" height="68" style="border:1px solid #eee;">';
                    html += '<input type="hidden" name="files[]" value="'+res.src+'" >';
                    html += '<div onclick="((this.parentNode).parentNode).removeChild(this.parentNode);" style="background-color:#000;position:absolute;top:0;right:0;padding:2px;"><i class="layui-icon" style="color:#fff;">&#x1007;</i></div>';
                    html += '</div>';
                $('#files-list').append(html);
                return true;
              }
            },
            error: function(){
              var errText = $('#files-err');
              errText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini files-reload">重试</a>');
              errText.find('.files-reload').on('click', function(){
              	errText.remove();
                uploadInst.upload();
              });
            }
          });
        });
      </script>
    </div>
  </div>

    
   
 
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">状态</label>
      <div class="layui-input-inline">
        <select name="status" required lay-verify="required" lay-filter="">
          <option value="1"  >已公开</option>
          <option value="0" >不公开</option>
        </select>
      </div>
    </div>
  </div>

  <div class="layui-footer">
    <button class="layui-btn layui-btn-normal layui-btn-small" lay-submit lay-filter="*" type="button">立即提交</button>
    <button class="layui-btn layui-btn-small layui-btn-primary" id="closeFrame" type="button">完成/取消</button>
  </div>

</form>
<script>
  layui.use(['layer','jquery','form','layedit'],function(){
    var $ = layui.jquery;
    var form = layui.form;
    var layedit = layui.layedit;

    layedit.set({
    	uploadImage:{
    		url: '{:url('upload/articleImage')}',type:'post'
    	}
    })
    var editIndex = layedit.build('content');
    form.verify({
      title:function(value){if(value.length < 4){return '标题至少得4个字符啊';}},
      mobile: [ /^[\S]{7,15}$/,'电话必须7到15位，且不能出现空格']
      
    });

    //监听提交
    form.on('submit(*)', function(data){
      data.form.submit();
      return true;
    });
    $('#closeFrame').on('click',function(){
      parent.layer.closeAll();
    })
    $('#addData').on('click',function(){
      $('form').submit();
    })
  });
</script>
{/block}
{block name="script"}
{/block}
